package com.hd.service.impl;

import com.hd.controller.dto.ViewLiuChengDto;
import com.hd.mapper.CaseIllnessRelationMapper;
import com.hd.mapper.CaseMapper;
import com.hd.mapper.IllnessMapper;
import com.hd.pojo.Case;
import com.hd.pojo.CaseIllnessRelation;
import com.hd.pojo.Illness;
import com.hd.service.CaseService;
import com.hd.service.IllnessService;
import com.hd.tools.Pager;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by 1 on 2017/11/24.
 */
@Service("caseService")
@Transactional
public class CaseServiceImpl implements CaseService{

    @Resource
    private CaseMapper caseMapper;

    @Resource
    private IllnessService illnessService;

    @Resource
    private CaseIllnessRelationMapper caseIllnessRelationMapper;

    @Override
    public Integer searchCaseNoNum(Integer memberId) {
        return caseMapper.searchCaseNoNum(memberId);
    }

    @Override
    public Integer addCase(Case ca,String[] illnessName,String[] illnessResult) {
        Integer i = caseMapper.add(ca);
        for(int j=0;j<illnessName.length;j++) {
            Illness illness = new Illness();
            illness.setIllnessName(illnessName[j]);
            illness.setIllnessResult(illnessResult[j]);
            i = illnessService.addIllness(illness);
            CaseIllnessRelation cir = new CaseIllnessRelation();
            cir.setCaseId(ca.getCaseId());
            cir.setIllnessId(illness.getIllnessId());
            i = caseIllnessRelationMapper.add(cir);
        }
        return i;
    }

    @Override
    public Pager searchViewLiuCheng(Integer offset,Integer limit,ViewLiuChengDto dto) {
        Pager pager = new Pager();
        pager.setRows(caseMapper.searchViewLiuCheng(offset,limit,dto));
        pager.setTotal(caseMapper.getTotal(dto));
        return pager;
    }


}
